#include <iostream>

namespace audio
{
	namespace effects
	{
		template <typename T>
		void threshold(T* begin, T* end, T middle, T width)
		{
			for(T* index=begin; index<end; ++index)
			{
				if(*index<middle+width && *index>middle-width)
				{
					*index=middle;
				}
			}
		}

		template <typename T>
		void distortion(T* begin, T* end, T middle, T width)
		{
			for(T* index=begin; index<end; ++index)
			{
				if(*index>middle+width)*index=middle+width;
				if(*index<middle-width)*index=middle-width;
			}
		}

		template <typename T>
		void normalize(T* begin, T* end, T middle, T amplitude)
		{
			T max=middle;
			double k;
			for(T* index=begin; index<end; ++index)
			{
				if(*index>max)max=*index;
			}
			k=(double)amplitude/(double)(max-middle);
			for(T* index=begin; index<end; ++index)
			{
				(*index)=(double)(*index-middle)*k+middle;
			}
		}
	}
}